package com.huawei.appmarket.service.settings.activity;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.ShareInfo;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.e;
import com.huawei.appgallery.foundation.ui.framework.fragment.LoadingFragment;
import com.huawei.appgallery.foundation.ui.framework.titleframe.bean.BaseTitleBean;
import com.huawei.appgallery.foundation.ui.framework.titleframe.bean.SpinnerItem;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appmarket.service.appdetail.bean.report.GeneralResponse;
import com.huawei.appmarket.service.appdetail.bean.report.GeneralResponse$LevelBean;
import com.huawei.appmarket.service.appdetail.bean.report.GeneralResponse.GradeData;
import com.huawei.appmarket.service.appdetail.bean.report.GeneralResponse.GradeInfo;
import com.huawei.appmarket.service.settings.view.ContentGradeListActivityProtocol;
import com.huawei.appmarket.service.settings.view.activity.GradeListDescriptionActivityProtocol;
import com.huawei.appmarket.service.settings.view.activity.GradeListDescriptionActivityProtocol.Request;
import com.huawei.appmarket.service.settings.view.widget.GradeInfoTitle;
import com.huawei.appmarket.service.settings.view.widget.GradeItemView;
import huawei.widget.HwButton;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import o.azb;
import o.cjf;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cks;
import o.cku;
import o.cvt;
import o.der;
import o.der.a;
import o.der.f;
import o.der.g;
import o.djb;
import o.Logger;
import o.drh;
import o.dzy;
import o.efy;
import o.efz;
import o.ege;
import o.egp;
import o.egv;
import o.ehd;
import o.CollectCheck;
import o.eqx;
import o.euf;
import o.eyo;

public class ContentGradeListActivity extends BaseActivity<ContentGradeListActivityProtocol> implements com.huawei.appmarket.service.settings.view.widget.GradeItemView.d, o.ege.d, o.efy.c, e {
    private GradeData ʻॱ;
    private ege ʽॱ;
    private GeneralResponse$LevelBean ʾ;
    private cku ʿ;
    private String ˈ;
    private GradeInfoTitle ˊˊ;
    private efy ˊˋ;
    private LinearLayout ˊॱ;
    private long ˋॱ;
    private HwButton ˏॱ;
    private int ͺ = -1;
    private List<GradeItemView> ॱˊ;
    private boolean ॱˋ = false;
    private efz ॱˎ;
    private String ᐝॱ;

    class c implements OnClickListener {
        final /* synthetic */ ContentGradeListActivity ॱ;

        private c(ContentGradeListActivity contentGradeListActivity) {
            this.ॱ = contentGradeListActivity;
        }

        public void onClick(View view) {
            this.ॱ.ˊˋ.ˊ(this.ॱ.ͺ, this.ॱ.ᐝॱ);
        }
    }

    class d implements cks {
        int ˋ;
        final /* synthetic */ ContentGradeListActivity ˎ;

        d(ContentGradeListActivity contentGradeListActivity, int i) {
            this.ˎ = contentGradeListActivity;
            this.ˋ = i;
        }

        public void enableNetworking() {
            switch (this.ˋ) {
                case 1:
                    this.ˎ.ˍ();
                    return;
                case 2:
                    this.ˎ.ˊˋ.ˎ();
                    return;
                default:
                    return;
            }
        }

        public void upgrade() {
        }

        public void ˋ() {
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (ˋˊ()) {
            getWindow().addFlags(8192);
            setContentView(g.ॱᐝ);
            getWindow().getDecorView().setBackgroundColor(getResources().getColor(a.ᐝ));
            azb.ˋ(findViewById(o.der.d.ˈᐝ));
            this.ॱˊ = new ArrayList();
            this.ˊॱ = (LinearLayout) findViewById(o.der.d.ॱˈ);
            this.ˏॱ = (HwButton) findViewById(o.der.d.ᐨ);
            this.ˏॱ.setEnabled(false);
            ॱ(getString(f.ˉ));
            this.ˏॱ.setOnClickListener(new c());
            this.ॱˋ = euf.ˎ().ˏ("content_restrict_first_change_level", true);
            this.ॱˎ = (efz) egv.ॱᐝ();
            this.ͺ = this.ॱˎ.ॱˊ();
            this.ˈ = ((ContentGradeListActivityProtocol) ʾ()).ˋ().ˎ();
            this.ˊˋ = egp.ˋ(((ContentGradeListActivityProtocol) ʾ()).ˋ().ˊ(), this.ˈ);
            this.ˊˋ.ॱ(((ContentGradeListActivityProtocol) ʾ()).ˋ().ॱ());
            this.ˊˋ.ॱ((o.efy.c) this);
            this.ˊˋ.ˎ(this.ͺ);
            Logger.ˎ("ActivityGradeList", "onCreate gradeID:" + this.ͺ);
            this.ʽॱ = new ege(this);
            if (TextUtils.isEmpty(this.ˈ)) {
                this.ʽॱ.ॱ(true);
            }
            if (bundle != null) {
                this.ͺ = bundle.getInt("save_grade");
                this.ʽॱ.ॱ(bundle.getBoolean("save_hasAuth"));
            }
            ˊˊ();
            return;
        }
        finish();
    }

    private boolean ˋˊ() {
        return (!(egv.ॱᐝ() instanceof efz) || ʾ() == null || ((ContentGradeListActivityProtocol) ʾ()).ˋ() == null) ? false : true;
    }

    public void onPause() {
        super.onPause();
        ˎˏ();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        this.ˊˋ.ॱ();
        return true;
    }

    public void ᐝ() {
        finish();
    }

    public void ͺ() {
        ˏ(2);
    }

    private void ˋ(Context context, GradeData gradeData) {
        if (gradeData != null) {
            cjo gradeListDescriptionActivityProtocol = new GradeListDescriptionActivityProtocol();
            gradeListDescriptionActivityProtocol.ˊ(new Request());
            gradeListDescriptionActivityProtocol.ॱ().ˎ(gradeData);
            cjk.ˎ().ˋ(context, new cjm("gradedescription.activity", gradeListDescriptionActivityProtocol));
        }
    }

    private void ˊˊ() {
        GradeInfo ˊ = dzy.ˊ();
        if (ˊ(ˊ)) {
            ͺॱ();
        } else {
            ˎ(ˊ);
        }
    }

    private void ˎ(GradeInfo gradeInfo) {
        if (gradeInfo != null) {
            GradeData ˏ = gradeInfo.ˏ();
            this.ʻॱ = ˏ;
            ˊ(ˏ);
            if (this.ˊˊ != null) {
                this.ˊˊ.ॱˋ();
            }
        } else if (this.ˊˊ != null) {
            this.ˊˊ.ʻॱ();
        }
    }

    private void ˊ(GradeData gradeData) {
        if (gradeData != null) {
            this.ˊˋ.ॱ(gradeData.ˏ());
            GeneralResponse$LevelBean generalResponse$LevelBean = null;
            Collection ॱ = gradeData.ॱ();
            if (!CollectCheck.isEmpty(ॱ)) {
                List arrayList = new ArrayList(ॱ);
                arrayList.add(ˎˎ());
                int i = 0;
                while (i < arrayList.size()) {
                    GeneralResponse$LevelBean generalResponse$LevelBean2 = (GeneralResponse$LevelBean) arrayList.get(i);
                    generalResponse$LevelBean2.ˏ(i);
                    ˋ(generalResponse$LevelBean2, arrayList.size());
                    if (generalResponse$LevelBean2.ˏ() == this.ͺ) {
                        Logger.ˏ("ActivityGradeList", "composeView: cache bean");
                    } else {
                        generalResponse$LevelBean2 = generalResponse$LevelBean;
                    }
                    i++;
                    generalResponse$LevelBean = generalResponse$LevelBean2;
                }
                if (generalResponse$LevelBean != null) {
                    ˏ(generalResponse$LevelBean);
                }
            }
        }
    }

    private void ˋ(GeneralResponse$LevelBean generalResponse$LevelBean, int i) {
        View gradeItemView = new GradeItemView(this);
        gradeItemView.setTag(generalResponse$LevelBean);
        gradeItemView.setListener(this);
        gradeItemView.ˋ().setText(generalResponse$LevelBean.ˎ());
        this.ˊॱ.addView(gradeItemView);
        this.ॱˊ.add(gradeItemView);
        int ॱ = generalResponse$LevelBean.ॱ();
        gradeItemView.setSubTitle(generalResponse$LevelBean.ʼ());
        if (ॱ == i - 1) {
            gradeItemView.ˏ().setVisibility(8);
        }
        if (generalResponse$LevelBean.ˏ() == 0) {
            gradeItemView.ˎ().setImageResource(der.e.ᐝ);
        } else {
            eqx.ˏ(gradeItemView.ˎ(), generalResponse$LevelBean.ˊ(), "defaultPresetResourceKey");
        }
    }

    private GeneralResponse$LevelBean ˎˎ() {
        GeneralResponse$LevelBean generalResponse$LevelBean = new GeneralResponse$LevelBean();
        generalResponse$LevelBean.ˎ(0);
        generalResponse$LevelBean.ˎ(getString(f.ˈ));
        generalResponse$LevelBean.ˊ(getString(f.ˊˋ));
        generalResponse$LevelBean.ˊ(0);
        return generalResponse$LevelBean;
    }

    private void ˏ(GeneralResponse$LevelBean generalResponse$LevelBean) {
        Logger.ˏ("ActivityGradeList", "reLayoutByChosenItem: " + generalResponse$LevelBean.ˏ());
        if (this.ॱˊ != null && this.ॱˊ.size() > 0) {
            for (int i = 0; i < this.ॱˊ.size(); i++) {
                boolean z;
                GradeItemView gradeItemView = (GradeItemView) this.ॱˊ.get(i);
                if (i == generalResponse$LevelBean.ॱ()) {
                    z = true;
                } else {
                    z = false;
                }
                gradeItemView.setChecked(z);
            }
            this.ͺ = generalResponse$LevelBean.ˏ();
            this.ᐝॱ = generalResponse$LevelBean.ˎ();
            if (this.ͺ != this.ॱˎ.ॱˊ()) {
                this.ˏॱ.setEnabled(true);
            }
        }
    }

    public void ॱ(GeneralResponse$LevelBean generalResponse$LevelBean) {
        if (generalResponse$LevelBean != null && generalResponse$LevelBean.ˏ() != this.ͺ) {
            this.ʾ = generalResponse$LevelBean;
            if (this.ʽॱ.ॱ()) {
                Logger.ˏ("ActivityGradeList", "onChoose: authed");
                ˏ(generalResponse$LevelBean);
                ˋˋ();
                return;
            }
            Logger.ˏ("ActivityGradeList", "onChoose: not authed");
            long currentTimeMillis = System.currentTimeMillis();
            if (currentTimeMillis - this.ˋॱ >= 1000) {
                this.ˋॱ = currentTimeMillis;
                this.ʽॱ.ˎ();
            }
        }
    }

    private void ˋˋ() {
        if (this.ॱˋ) {
            cku ˋ = cku.ˋ(getString(f.ˌॱ), getString(f.ˋˊ));
            ˋ.ॱ(-1, getResources().getString(f.ᐝʽ));
            ˋ.ˎ(-2, 8);
            ˋ.ˎ(this);
            this.ॱˋ = false;
            euf.ˎ().ˋ("content_restrict_first_change_level", false);
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        bundle.putInt("save_grade", this.ͺ);
        if (this.ʽॱ != null) {
            bundle.putBoolean("save_hasAuth", this.ʽॱ.ॱ());
        }
        super.onSaveInstanceState(bundle);
    }

    public cjf ˊ(String str) {
        BaseTitleBean baseTitleBean = new BaseTitleBean();
        baseTitleBean.ॱ(str);
        this.ˊˊ = new GradeInfoTitle(this, baseTitleBean);
        this.ˊˊ.ॱ(new djb(this) {
            final /* synthetic */ ContentGradeListActivity ˋ;

            {
                this.ˋ = r1;
            }

            public void ˊ(SpinnerItem spinnerItem) {
            }

            public void ʼʽ() {
                this.ˋ.ˋ(this.ˋ, this.ˋ.ʻॱ);
            }

            public void ˋ(ShareInfo shareInfo) {
            }
        });
        return this.ˊˊ;
    }

    private void ˏ(int i) {
        cku ˋ = cku.ˋ(null, getString(f.ˊᐝ, new Object[]{this.ˈ}));
        ˋ.ˎ(-2, 8);
        ˋ.ॱ(new d(this, i));
        ˋ.ˎ(this);
        ˋ.ॱ(-1, getString(f.ᐝʽ));
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        boolean z = true;
        super.onActivityResult(i, i2, intent);
        Logger.ˏ("ActivityGradeList", String.format(Locale.ENGLISH, "onActivityResult: requestCode:%s resultCode:%s", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)}));
        if (i == 1003) {
            ege o_ege = this.ʽॱ;
            if (i2 != -1) {
                z = false;
            }
            o_ege.ˎ(z);
        }
    }

    private ehd ˋᐝ() {
        ehd o_ehd = new ehd(this);
        o_ehd.ˎ(new o.ehd.d(this) {
            final /* synthetic */ ContentGradeListActivity ˏ;

            {
                this.ˏ = r1;
            }

            public void ॱ() {
                this.ˏ.ʽॱ.ˊ(true);
            }

            public void ˎ() {
                this.ˏ.ʽॱ.ˊ(false);
            }
        });
        return o_ehd;
    }

    public void ॱˊ() {
        Logger.ˏ("ActivityGradeList", "showInnerVerifyPasswdUI: ");
        ˋᐝ().ˎ((Activity) this);
    }

    public void ᐝॱ() {
        Logger.ˏ("ActivityGradeList", "showInnerSetPasswdUI: ");
        ˋᐝ().ˊ((Activity) this);
    }

    public void onBackPressed() {
        Logger.ˏ("ActivityGradeList", "onBackPressed: ");
        this.ˊˋ.ॱ();
    }

    public void ʼॱ() {
        Logger.ˏ("ActivityGradeList", "showOuterVerifyPasswdUI: ");
        try {
            Intent intent = new Intent();
            intent.setClassName("com.huawei.parentcontrol", "com.huawei.parentcontrol.ui.activity.ConfirmPasswordActivity");
            intent.putExtra("fromWhere", "apprating");
            startActivityForResult(intent, 1003);
        } catch (ActivityNotFoundException e) {
            Logger.e("ActivityGradeList", e.toString());
        } catch (SecurityException e2) {
            Logger.e("ActivityGradeList", e2.toString());
        }
    }

    public void ˊᐝ() {
        Logger.ˏ("ActivityGradeList", "showOuterSetPasswdUI: ");
        ˌ();
        this.ʿ = cku.ˋ(null, getString(f.ˊˊ));
        this.ʿ.ॱ(new d(this, 1));
        this.ʿ.ˎ(this);
        this.ʿ.ॱ(-1, getString(f.ˋᐝ));
        this.ʿ.ॱ(-2, getString(f.ॱʾ));
    }

    private void ˍ() {
        Logger.ˏ("ActivityGradeList", "startSystemHealthyUsePhoneActivity:");
        Intent intent = new Intent();
        intent.setFlags(268435456);
        intent.setClassName("com.huawei.parentcontrol", "com.huawei.parentcontrol.ui.activity.HomeActivity");
        try {
            startActivityForResult(intent, 1001);
        } catch (ActivityNotFoundException e) {
            Logger.ˋ("ActivityGradeList", e.getMessage());
        }
    }

    public void ˊˋ() {
        Logger.ˏ("ActivityGradeList", "onAuthSuccess: ");
        ˏ(this.ʾ);
        ˋˋ();
    }

    public void ˉ() {
        Logger.ˏ("ActivityGradeList", "onAuthFailed: ");
    }

    private void ˌ() {
        if (this.ʿ != null && this.ʿ.isAdded()) {
            this.ʿ.dismiss();
            this.ʿ = null;
        }
    }

    private void ˎˏ() {
        if (!this.ॱˎ.ॱˎ()) {
            cku.ˎ(this, "content_restrict");
        }
    }

    private void ͺॱ() {
        TaskFragment loadingFragment = new LoadingFragment();
        loadingFragment.ʼ(new Bundle());
        loadingFragment.ˋ(ˏॱ(), o.der.d.ﹳ, "TaskFragment");
    }

    public void ˎ(TaskFragment taskFragment, List<cvt> list) {
        list.add(new drh("grade"));
    }

    public boolean ˋ(TaskFragment taskFragment, b bVar) {
        if (bVar == null || bVar.ˋ == null || bVar.ˋ.getResponseCode() != 0 || bVar.ˋ.getRtnCode_() != 0) {
            if ((taskFragment instanceof LoadingFragment) && bVar != null) {
                LoadingFragment loadingFragment = (LoadingFragment) taskFragment;
                ResponseBean responseBean = bVar.ˋ;
                if (responseBean == null || responseBean.getResponseCode() != ResponseBean.SERVER_DELAY_RETRY) {
                    eyo ॱ = eyo.ॱ(bVar.ˊ, responseBean, null);
                    loadingFragment.ˏ(ॱ.ˊ(), ॱ.ᐝ());
                } else {
                    loadingFragment.ॱ(responseBean.getResponseCode(), true);
                }
            }
        } else if (bVar.ˋ instanceof GeneralResponse) {
            GradeInfo ॱॱ = ((GeneralResponse) bVar.ˋ).ॱॱ();
            dzy.ॱ(ॱॱ);
            ˎ(ॱॱ);
            taskFragment.ॱ(ˏॱ());
        } else {
            Logger.ˋ("ActivityGradeList", "response.responseObj is not instance of GeneralResponse");
        }
        return false;
    }

    private boolean ˊ(GradeInfo gradeInfo) {
        return gradeInfo == null || gradeInfo.ˏ() == null || CollectCheck.isEmpty(gradeInfo.ˏ().ॱ());
    }
}
